<template>
       <div style="font-size: 16px;font-weight: 600;">
        <el-radio></el-radio>呼叫黑名单
    </div>
  <el-form :inline="true" :model="state.dataForm" @keyup.enter="state.getDataList()" style="margin-top: 10px;">
    <el-form-item label="手机号:">
      <el-input v-model="state.dataForm.phone" type="text" clearable placeholder="请输入" style="width: 220px;"></el-input>
    </el-form-item>
    <!-- 查询 -->
    <el-form-item>
      <el-button @click="state.getDataList()" type="primary">{{ $t("query") }}</el-button>
    </el-form-item>
    <!--新增-->
    <el-form-item v-if="state.hasPermission('crm:noccallblacklist:save')">
      <el-button @click="addOrUpdateHandle()" type="primary">{{ $t("add") }}</el-button>
    </el-form-item>
    <!--编辑-->
    <el-form-item v-if="state.hasPermission('crm:noccallblacklist:update')">
      <el-button @click="addOrUpdateHandle()" :disabled="state.single" type="primary">{{ $t("编辑") }}</el-button>
    </el-form-item>
    <!-- 删除 -->
    <el-form-item>
      <el-button v-if="state.hasPermission('crm:noccallblacklist:delete')" type="danger"
        @click="state.deleteHandle()">{{ $t("deleteBatch") }}</el-button>
    </el-form-item>
    <el-table :header-cell-style="{ 'background': '#eef1f6', 'color': '#1f2d3d', 'border-color': '#dfe6ec' }"
      v-loading="state.dataListLoading" :data="state.dataList" border
      @selection-change="state.dataListSelectionChangeHandle" style="width: 100%">
      <el-table-column type="selection"></el-table-column>
      <el-table-column align="center" prop="id" label="id"></el-table-column>
      <el-table-column align="center" prop="phone" label="手机号"></el-table-column>
      <el-table-column align="center" prop="createTime" label="时间"></el-table-column>
      <el-table-column align="center" prop="remark" label="备注"></el-table-column>
    </el-table>
  </el-form>
  <el-pagination :current-page="state.page" :page-sizes="[10, 20, 50, 100]" :page-size="state.limit"
    :total="state.total" layout="total, sizes, prev, pager, next, jumper" @size-change="state.pageSizeChangeHandle"
    @current-change="state.pageCurrentChangeHandle"> </el-pagination>
  <!-- 弹窗, 新增 / 修改 -->
  <add-or-update :key="addKey" ref="addOrUpdateRef" @refreshDataList="state.getDataList"></add-or-update>
</template>

<script lang="ts" setup>
import baseService from "@/service/baseService";
import { ElMessage } from "element-plus"
import { useRouter } from 'vue-router'
import useView from "@/hooks/useView";
import { nextTick, reactive, ref, toRefs, watch } from "vue";
import AddOrUpdate from "./call-blacklist-add-update.vue";
const view = reactive({
  getDataListURL: '/crm/noccallblacklist/page',
  getDataListIsPage: true,
  deleteURL: "/crm/noccallblacklist",
  deleteIsBatch: true,
  dataForm: {
    id: "",
    phone: "",
  },

});


const addKey = ref(0);
const ida = ref(0);
const addOrUpdateRef = ref();

const addOrUpdateHandle = (id?: number) => {
  addKey.value++;
  if (state.dataListSelections) {
    if (Object.keys(state.dataListSelections).length === 0) {
      nextTick(() => {
        addOrUpdateRef.value.init(id);
      });
    } else {
      ida.value = state.dataListSelections[0].id
      nextTick(() => {
        addOrUpdateRef.value.init(Number(ida.value));
      });
    }
  }
};

const state = reactive({ ...useView(view), ...toRefs(view) });
</script>
<style lang="scss" scoped>
::v-deep .el-table .cell {
  white-space: nowrap;
}
</style>
